<template>
  <div>
    <div class="page-content">
      <div class="user_head">
        <div class="user-content">
          <img @click="$router.togo('/mine/setting')" :src="showImg" alt="" class="u_img">
          <div class="name">
            <p>{{userInfo.name}}</p>
            <p>({{userInfo.ccount}})</p>
          </div>
        </div>
      </div>
      <div class="item_ka">
        <ul>
          <li>
            <p>{{comments_num}}</p>
            <p>评论数</p>
          </li>
          <li>
            <p>{{dot_num}}</p>
            <p>点赞数</p>
          </li>
        </ul>
      </div>
      <div class="list">
        <ul>
          <li v-for="(item, index) in list" :key="index" @click="$router.togo(item.path)">
            <div class="l">
              <img :src="require('../assets/images/' + item.ico + '.png' )" alt="" class="ico">
              <p>{{item.name}}</p>
            </div>
            <div class="more">
              <img src="../assets/images/ico_more.png" alt="">
            </div>
          </li>
        </ul>
      </div>
      <button class="logout" @click="logOut">
        <img src="../assets/images/ico_logout.png" alt="">
        <p>退出登录</p>
      </button>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      title: '我的',
      list: [
        {name: '我的留言', ico: 'ico_liu', path: '/mine/my_mimi'},
        {name: '修改密码', ico: 'ico_set_pwd', path: '/mine/set_pwd'},
      ],
			comments_num: 0,
			dot_num: 0
    }
  },
  computed: {
  	...mapState(['hasLogin', 'userInfo']),
		showImg(){
			if(this.userInfo.u_img){
				return require('../assets/images/tou/' + this.userInfo.u_img + '.png')
			} else {
				return require('../assets/images/tou/1.png')
			}
		}
  },
  methods: {
		...mapMutations(['logout']),
    logOut () {
			this.$msgBox.showMsgBox('确定要退出登录吗？').then(val => {
				this.logout();
				this.$router.toReplace('/login');				
			}).catch(() => {})
    },
		getData(){
			this.$loading.show();
			this.$http.user_data({
				token: this.userInfo.token,
				u_id: this.userInfo.id
			}).then((res) => {
				this.$loading.hide();
				console.log(res);
				if(res.code === 0){
					this.comments_num = res.data.comments_num;
					this.dot_num = res.data.dot_num;
				} else {
					this.$toast(res.msg);
				}
			})
		}
  },
  mounted () {
		this.getData()
  }
}
</script>

<style scoped lang="scss">
@import 'styles/common.scss';
.user_head{
  background-image: url('../assets/images/ico_mine_bg.png');
  width: 100%;
  height: rem(348);
  background-size: cover;
  .user-content{
    padding-top: rem(60);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: calc(100% - 30px);
    margin-left: 15px;
    .u_img{
      width: rem(140);
      height: rem(140);
      border-radius: 50%;
    }
    .name{
      p{
        font-size: rem(38);
        font-weight: bold;
        color: #3f51b5;
        margin-left: rem(40);
        &:nth-last-child(1){
          font-size: rem(26);
          opacity: .6;
          margin-top: rem(10);
        }
      }
    }
  }
}
.item_ka{
  position: relative;
  top: rem(-100);
  box-shadow: 0 rem(4) rem(8) rgba(0,0,0,.1);
  width: calc(100% - 60px);
  margin-left: 30px;
  background: #fff;
  border-radius: rem(20);
  ul{
    display: flex;
    justify-content: space-around;
    align-content: center;
    padding: rem(40) 0;
    li{
      p:nth-child(1){
        margin-bottom: rem(20);
        font-size: rem(40);
        color: #3f51b5;
        font-weight: bold;
      }
    }
  }
}
.list{
  ul{
    width: calc(100%  - 40px);
    padding: 0 20px;
    background: #fff;
    li:not(:nth-last-child(1)){
      border-bottom: 1px solid #eee;
    }
    li{
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: rem(110);
      line-height: rem(110);
      .l{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        img{
          width: rem(50);
          margin-right: rem(20);
        }
      }
      .more{
        img{
          width: rem(30);
        }
      }
    }
  }
}
.logout{
  width: calc(100% - 80px);
  margin-left: 40px;
  background: #FF5722;
  margin-top: rem(80);
  display: flex;
  justify-content: center;
  align-items: center;
  p{
    color: #fff;
    font-size: rem(30);
  }
  img{
    width: rem(50);
    margin-right: rem(20);
  }
}
</style>
